﻿using StockTools.ViewModel;
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace StockTools.Modules
{
    /// <summary>
    /// StockMonitor.xaml 的交互逻辑
    /// </summary>
    public partial class StockMonitor : UserControl
    {
        private DispatcherTimer dt = new DispatcherTimer();


        StockMonitorViewModel vm = new StockMonitorViewModel();
        public StockMonitor()
        {
            InitializeComponent();
            this.DataContext = vm;
            dt.Tick += new EventHandler(dt_Tick);

        }
        void dt_Tick(object sender, EventArgs e)
        {
            vm.Refurbish();
        }

        private void UserControl_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (Convert.ToBoolean(e.NewValue))
            {
                dt.Start();
                dt.Interval = TimeSpan.FromMilliseconds(5000);

            }
            else
            {
                dt.Stop();
            }
        }
    }
}
